<?php

use console\db\Migration;

/**
 * 创建单位相关信息表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m190102_100001_t_company extends Migration {

    /**
     * 单位信息表
     * @table `company`
     */
    public function buildTableCompany() {
        return [
            'comment' => '单位信息表',
            'columns' => [
                'id' => $this->primaryKey(),
                'parent_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('上级单位ID'),
                'name' => $this->string(100)->notNull()->comment('单位名称'),
                'abbr' => $this->string(50)->defaultValue('')->comment('单位简称'),
                'type' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('单位类型'),
                'province' => $this->string(50)->comment('省'),
                'city' => $this->string(50)->comment('市'),
                'dist' => $this->string(50)->comment('区/县'),
                'mark' => $this->string(255)->comment('备注'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(0)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ];
    }

    /**
     * 变电站信息表
     * @table `substation`
     */
    public function buildTableSubstation() {
        return [
            'comment' => '变电站信息表',
            'columns' => [
                'id' => $this->primaryKey(),
                'company_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('直属公司ID'),
                'name' => $this->string(100)->notNull()->comment('变电站名称'),
                'voltage' => $this->string(100)->notNull()->comment('电压等级'),
                'voltage_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('电压等级ID'),
                'city_company_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('市属公司ID'),
                'province_company_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('省属公司ID'),
                'uuid' => $this->char(32)->comment('UUID'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(0)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ];
    }

    /**
     * 电压等级表
     * @table `voltage`
     */
    public function buildTableVoltage() {
        return [
            'comment' => '电压等级表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(100)->notNull()->comment('等级名称'),
                'volt' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('伏特数值'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(0)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ];
    }

    /**
     * 排查项目表
     * @table `category`
     */
    public function buildTableCategory() {
        return [
            'comment' => '排查项目表',
            'columns' => [
                'id' => $this->primaryKey(),
                'parent_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('父级项目ID'),
                'name' => $this->string(255)->notNull()->comment('项目名称'),
                'index' => $this->char(255)->comment('索引序号'),
                'description' => $this->string(255)->comment('描述/备注'),
                'inscene' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('现场检查'),
                'indata' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('资料检查'),
                'method' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('检查方式'),
                'status' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ];
    }

    /**
     * 隐患等级表
     * @table `danger_level`
     */
    public function buildTableDangerLevel() {
        return [
            'comment' => '隐患等级表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(255)->notNull()->comment('等级名称'),
                'description' => $this->string(255)->comment('描述'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(0)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ];
    }

}
